<?php 
if(user::active()->login)
{
	if($meta['email'] == user::get_user()->email OR user::active()->admin)
	{
		echo '<p class="fr"><a href="'.url::site('article/edit/'.$article_id).'">编辑</a> / <a class="delete" href="'.url::site('article/delete/'.$article_id).'">删除</a></p>';
	}
}
?>
<h1><?php $feedback_type = Kohana::config('site.feedback_type'); echo '['.$feedback_type[$meta['type']] .']' . $meta['title']; ?></h1>
<div id="vote" title="投一票" url="<?php echo url::site('article/vote/'.$article_id); ?>"><?php echo $meta['vote']; ?></div>
<div id="article" class="clear">
<?php echo nl2br2($content); ?><br /><br />
<p class="clearfix"></p>
<span id="status" class="fl" style="margin-right:10px"><?php $status = Kohana::config('site.feedback_status');echo $status[$meta['status']]; ?></span> 

<?php
if(user::active()->admin)
{
	$select_status = array('-1'=>'改变状态') + $status;
	echo form::dropdown('change_status',$select_status);
}
?>

<p class="user_meta gray"><?php if($user) {if(!empty($user->link)){echo html::anchor($user->link,$user->username);}else{echo $user->username;}} ?> <?php echo date::format($meta['pubdate']); ?></p>
</div>
<p id="comments_head"><?php if($comments) {echo count($comments).'条评论';} else {echo '暂无评论';} ?></p>
<?php if($comments){ ?>
<ul id="comments">
<?php foreach($comments as $comment){ ?>
<li <?php if($comment['email'] == Kohana::config('site.admin_email')) echo 'class="admin"'; ?>>
<?php
if(user::active()->login)
{
	if(user::get_user()->email == $comment['email'] OR user::active()->admin)
	{
		echo '<a href="'.url::site('article/delete_comment/'.$article_id.'/'.$comment['comment_id']).'" class="delete fr gray">&nbsp;x&nbsp;</a>';
	}
}
?>
<?php echo nl2br2($comment['content']); ?>
<p class="user_meta gray"><?php $user = user::get_user_info($comment['email']); if($user) {if($user->link){echo html::anchor($user->link,$user->username);}else{echo $user->username;}} ?> <?php echo date::format($comment['pubdate']); ?></p>
</li>
<?php } ?>
</ul>
<?php } ?>

<?php if(user::active()->login) { ?>
<form id="comment" method="post" action="<?php echo url::site('article/create_comment/'.$article_id) ?>">
<p><textarea name="content" title="我有话要说"></textarea></p>
<?php echo access::csrf_form_field();?>
<p><input type="submit" value="写好了" class="submit" /></p>
</form>
<?php } ?>

<script type="text/javascript">
$('a.delete').bind('click',function(e){
	e.preventDefault();
	var confirmed = confirm('确定要删除吗？');
	if(confirmed)
	{
		lzyy.post_to_url($(this).attr('href'));
	}
});
<?php if(user::has_voted($article_id) OR !user::active()->login){ ?>
$('#vote').css('cursor','default').attr('title','已经投过票啦');
<?php }else{ ?>
$('#vote').bind('click',function(e){
	e.preventDefault();
	var $self = $(this);
	$.post($self.attr('url'),{},function(data){
		if(data.status!='success')
		{
			alert('oops! something wrong happened!');
		}
		else
		{
			var vote_num = parseInt($self.text());
			$self.text(vote_num+1);
			$self.css('cursor','default').attr('title','已经投过票啦');
			$self.unbind('click');
		}
	},'json');
});
<?php } ?>
<?php if(user::active()->admin){ ?>
	$('#change_status').bind('change',function(){
		var value = $(this).val();
		location.href = '<?php echo url::site('article/change_status/'.$article_id); ?>/'+value;
	});
<?php } ?>
</script>
